﻿using System;
using System.Collections.Generic;

namespace FBGraph
{
    /// <summary>A marker interface for controllers that service "Primary" Graph API objects.</summary>
    /// <typeparam name="TModel">The type of Graph API object serviced by the controller.</typeparam>
    public interface IFBGraphPrimaryController<TModel> : IFBGraphController
        where TModel : class, IFBGraphResult, new() { }

    /// <summary>Contains extension methods for <see cref="IFBGraphPrimaryController{TModel}" />.</summary>
    public static class FBGraphPrimaryControllerExtensions
    {
        /// <summary>Gets the Graph object with the specified <paramref name="id" />.</summary>
        /// <param name="controller">A <see cref="IFBGraphPrimaryController{TModel}" />.</param>
        /// <param name="id">The Graph identifier or alias of the object that should be retrieved.</param>
        /// <returns>A <typeparamref name="TModel" /> object that has been deserialized from the JSON response of the GET request.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="id" /> was null.</exception>
        /// <exception cref="ArgumentException"><paramref name="id" /> was an empty string.</exception>
        public static TModel Get<TModel>(this IFBGraphPrimaryController<TModel> controller, Object id)
            where TModel : class, IFBGraphResult, new()
        {
            return controller.Context.GetSingle<TModel>(id, controller.GetFields());
        }

        /// <summary>Gets the Graph objects with the specified <paramref name="ids" />.</summary>
        /// <param name="controller">A <see cref="IFBGraphPrimaryController{TModel}" />.</param>
        /// <param name="ids">One or more Graph identifiers or aliases of the objects that should be retrieved.</param>
        /// <returns>A <see cref="Dictionary{Object, TModel}" /> of <typeparamref name="TModel" /> objects keyed by their identifiers that have been deserialized from the JSON response of the GET request.</returns>        
        /// <exception cref="ArgumentNullException"><paramref name="ids" /> was null.</exception>
        /// <exception cref="ArgumentException"><paramref name="ids" /> contained a null value or empty string.</exception>
        public static IDictionary<Object, TModel> Get<TModel>(this IFBGraphPrimaryController<TModel> controller, params Object[] ids)
            where TModel : class, IFBGraphResult, new()
        {
            return controller.Context.GetMany<TModel>(controller.GetFields(), ids);
        }
    }
}